//
//  YCRegisterNoticeViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/19.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  现场注册通知

#import "YCRegisterNoticeViewController.h"
#import "YCSignUpLocViewController.h"
#import "YCCarServiceViewController.h"
#import "YCNotificationDetailModel.h"

@interface YCRegisterNoticeViewController ()


/** 标题  */
@property (nonatomic, strong) UILabel *titleLabel;
/** 内容  */
@property (nonatomic, strong) UILabel *contentLabel;
/** 报名点查询  */
@property (nonatomic, strong) UIButton *signPlaceButton;
/** 前往班车  */
@property (nonatomic, strong) UIButton *comeCarButton;
/** 消息号  */
@property (nonatomic, assign) NSInteger nid;

/** 模型  */
@property (nonatomic, strong) YCNotificationDetailModel *detailModel;

@end

@implementation YCRegisterNoticeViewController
#pragma mark - 懒加载
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:20];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}

- (UILabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = [UIFont systemFontOfSize:14];
        _contentLabel.textColor = [UIColor yc_colorWithUInt:0x808080];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

- (UIButton *)comeCarButton
{
    if (!_comeCarButton) {
        _comeCarButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _comeCarButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _comeCarButton.layer.cornerRadius = 5;
        _comeCarButton.layer.masksToBounds = YES;
        _comeCarButton.layer.borderWidth = 1;
        _comeCarButton.layer.borderColor = [UIColor yc_colorWithUInt:0xf0f0f0].CGColor;
        _comeCarButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
        _comeCarButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        [_comeCarButton setImage:[UIImage imageNamed:@"班车查询"] forState:UIControlStateNormal];
        [_comeCarButton setTitle:@"前往班车" forState:UIControlStateNormal];
        [_comeCarButton setTitleColor:[UIColor yc_colorWithUInt:0x666666] forState:UIControlStateNormal];
        [_comeCarButton addTarget:self action:@selector(didTouchUpInsideCarSearchButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_comeCarButton];
    }
    return _comeCarButton;
}

- (UIButton *)signPlaceButton
{
    if (!_signPlaceButton) {
        _signPlaceButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _signPlaceButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _signPlaceButton.layer.cornerRadius = 5;
        _signPlaceButton.layer.masksToBounds = YES;
        _signPlaceButton.layer.borderWidth = 1;
        _signPlaceButton.layer.borderColor = [UIColor yc_colorWithUInt:0xf0f0f0].CGColor;
        _signPlaceButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
        _signPlaceButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        [_signPlaceButton setImage:[UIImage imageNamed:@"报名点查询"] forState:UIControlStateNormal];
        [_signPlaceButton setTitle:@"报名点查询" forState:UIControlStateNormal];
        [_signPlaceButton setTitleColor:[UIColor yc_colorWithUInt:0x666666] forState:UIControlStateNormal];
        [_signPlaceButton addTarget:self action:@selector(didTouchUpInsidePlaceSearchButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_signPlaceButton];
    }
    return _signPlaceButton;
}

#pragma mark - 生命周期
- (instancetype)initWithNid:(NSInteger)nid
{
    if (self = [super init]) {
        _nid = nid;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self yc_addLeftBarButtonItemWithTitle:@"关闭" target:self.navigationController action:@selector(popViewControllerAnimated:)];
    [self makeView];
    
    [self loadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)makeView
{
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.contentLabel];
    [self.view addSubview:self.signPlaceButton];
    [self.view addSubview:self.comeCarButton];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(100);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(100);
        make.left.equalTo(self.view).offset(20);
        make.right.equalTo(self.view).offset(-20);
    }];
    
    [self.signPlaceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        [YCAdapter performOtherBlock:^{
            make.bottom.equalTo(self.view.mas_bottom).offset(-100);
        } IPhone6Block:^{
            make.bottom.equalTo(self.view.mas_bottom).offset(-200);
        } IPhone6pBlock:^{
            make.bottom.equalTo(self.view.mas_bottom).offset(-230);
        }];
        make.width.equalTo(@120);
        make.height.equalTo(@35);
        make.centerX.equalTo(self.view).offset(-70);//60+10
    }];
    
    [self.comeCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.signPlaceButton);
        make.width.equalTo(self.signPlaceButton);
        make.height.equalTo(self.signPlaceButton);
        make.centerX.equalTo(self.view).offset(70);
    }];
}

#pragma mark - 数据处理

- (void)loadData
{
    NSDictionary *params = @{
                             @"uid":@"1",
                             @"token":accessToken_Test,
                             @"nid":@(self.nid),
                             };
    [[YCNetworManager shareManager] postWithUrl:YCAPINoticeListDetail params:params success:^(NSURLSessionDataTask *task, ServiceResponse *response) {
        self.detailModel = [YCNotificationDetailModel yc_objectWithKeyValues:response.data];
        dispatch_async(dispatch_get_main_queue(), ^{
            self.titleLabel.text = self.detailModel.title;
            self.contentLabel.text = self.detailModel.content;
        });
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        YCLog(@"%@",error.localizedDescription);
    }];
}




#pragma mark - 点击事件

/**
 *  报名点查询
 */
- (void)didTouchUpInsidePlaceSearchButton:(UIButton *)button
{
    YCLogFunc
    YCSignUpLocViewController *vc = [[YCSignUpLocViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

/**
 *  班车查询
 */
- (void)didTouchUpInsideCarSearchButton:(UIButton *)button
{
    YCLogFunc
    YCCarServiceViewController *vc = [[YCCarServiceViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
